import {Index_model} from 'index_model.js';

var index_model = new Index_model();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._loadData();
  },

  _loadData: function() {
    //获取banner信息
    index_model.getBanner((data)=> {
      this.setData({
        bannerArr:data.items
      });
    });

    //获取主题信息
    index_model.getTheme((data)=> {
      this.setData({
        themeArr:data,
        loadingHidden:true
      });
    });

    //获取最近新品接口
    index_model.getLatestProduct((data) => {
      this.setData({
        productArr:data
      });
    });
  },

  onThemesItemTap: function(event) {
    var id = index_model.getDataSet(event, 'id');
    var name = index_model.getDataSet(event, 'name');
    console.log(id);
    console.log(name);
  },

  onProductItemTap: function (event) {
    var id = index_model.getDataSet(event, 'id');

    wx.navigateTo({
      url: '../product/product?id='+id,
    })
  },
  //设置页面的分享信息
  onShareAppMessage: function() {
    return {
      title:"萌店",
      desc: "朋友圈的品质生活",
      path:"pages/home/index"
    }
  }
})